<?php

class Damages_Methods_Request_SendPerpetratorEmails extends Damages_Methods_Request {

  /**
   *
   * @var int[]
   */
  public $ids = array();

  /**
   *
   * @var string 
   */
  public $template;

  /**
   *
   * @var int 
   */
  public $templateId;

  public function __construct($params) {
    parent::__construct($params);
    $this->ids = $params->ids->toArray();
    $this->template = $params->template;
    $this->templateId = $params->templateId;
  }

  public function process() {
    $error = array();

    foreach ($this->ids as $id) {
      try {
        $request = new Damages_Methods_Request_SendPerpetratorEmail();
        $request->id = $id;
        $request->template = $this->template;
        $request->templateId = $this->templateId;
        $request->process();
      } catch (Exception $exc) {
        $error[] = $id;
        continue;
      }
    }
    if ($error)
      throw new Damages_Exception_App(Damages_Codes::MULTIPLE_EMAIL_SEND_FAILED, array(implode (', ', $error)));
    return new Damages_Methods_Response(true);
  }

}